﻿<?php
@session_start();

require_once("../../class/mysql.class.php");

  $obj = new Mysql();
  
  $obj -> set_table('user_login');
  $obj -> set_colone("(`*`)");
  $obj -> set_variables(" id_login = '" . $_SESSION["id"] . "' ");
  $user = $obj -> select_enregistrement();


	
	$ref_article= addslashes($_REQUEST["ref_article"]);
	$article_id= addslashes($_REQUEST["id_article"]);
	$type_id = addslashes($_REQUEST["id_type"]); 
	$emplacement_id = addslashes($_REQUEST["id_emplacement"]); 
	$prix = addslashes($_REQUEST["prix"]);
	$designation = addslashes($_REQUEST["designation"]); 	
	$date_add = addslashes($_REQUEST["date_ajout"]);
	//$id_type_monnaie = addslashes($_REQUEST["type_monnaie"]); 
	$commentaire = addslashes($_POST["comment"]); 
	//$id_fournisseur = addslashes($_REQUEST["id_fournisseur"]); 
	//$quantite = addslashes($_REQUEST["qte"]; 
	$qte_min = addslashes($_REQUEST["qte_min"]); 
	$id_unit_stockage = addslashes($_REQUEST["id_unit"]); 
	$id_user = $user['id_login'];
	
	//echo "<h1>-->".$_FILES['photo_article']['name']."</h1><br>";

	
	$obj = new Mysql ();
	$result = mysql_query("SELECT * FROM `st_article` WHERE id_article='".$article_id."'");
	$photo = mysql_fetch_object($result);

  	echo $photo->photo_name.'<br>';

	
	if ($_FILES['photo_article']['error']) 
		{     
				  switch ($_FILES['photo_article']['error']){     
						   case 1: // UPLOAD_ERR_INI_SIZE     
						   echo"Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !";     
						   break;     
						   case 2: // UPLOAD_ERR_FORM_SIZE     
						   echo "Le fichier dépasse la limite autorisée dans le formulaire HTML !"; 
						   break;     
						   case 3: // UPLOAD_ERR_PARTIAL     
						   echo "L'envoi du fichier a été interrompu pendant le transfert !";     
						   break;     
						   case 4: // UPLOAD_ERR_NO_FILE     
						   echo "Le fichier que vous avez envoyé a une taille nulle !"; 
						   break;     
				}

				$photoName = $photo->photo_name;
				

			}  
			elseif (isset($_FILES['photo_article']['tmp_name'])&&($_FILES['photo_article']['error'] == 0)) 
			{     
				 
					$chemin_destination = '../../article_pic/'.date('Y').'/'.date('m').'/'.date('d').'/';
					$ext = explode('.',$_FILES['photo_article']['name']);
					$extension = $ext[1];					
					move_uploaded_file($_FILES['photo_article']['tmp_name'], $chemin_destination.$ref_article.'_'.$_FILES['photo_article']['name']);     

			$photoName = 'article_pic/'.date('Y').'/'.date('m').'/'.date('d').'/'.$ref_article.'_'.$_FILES['photo_article']['name'];		
			   
			}
			echo $photoName;			
			
			if(empty($_FILES['photo_article']['name']))
			{
			$obj = new Mysql ();				
	echo	$sql ="UPDATE `st_article` SET `ref_article`='".$ref_article."',`designation`='".$designation."',
			`id_user`='".$id_user."',`id_type`='".$type_id."',`id_lieu`='".$emplacement_id."',
			`id_unite_stockage`='".$id_unit_stockage."',`last_modif`='".date('Y-m-d H:i:s')."',
			`prix`='".$prix."',`commentaire`='".$commentaire."',`date_add`='".$date_add."',
			`Qte_min`='".$qte_min."',`Qte_min`='".$qte_min."',photo_name='".$photoName."',`last_user_modif`='".date('Y-m-d H:i:s')."' 
			WHERE id_article='".$article_id."'";
			
			mysql_query($sql);
			
			}
			else
			{
			$obj = new Mysql ();				
			echo	$sql ="UPDATE `st_article` SET `ref_article`='".$ref_article."',
			`designation`='".$designation."',`id_user`='".$id_user."',`id_type`='".$type_id."',`id_lieu`='".$emplacement_id."',
			`id_unite_stockage`='".$id_unit_stockage."',`last_modif`='".date('Y-m-d H:i:s')."',
			`prix`='".$prix."',`commentaire`='".$commentaire."',`date_add`='".$date_add."',
			`Qte_min`='".$qte_min."',photo_name='".$photoName."',`last_user_modif`='".date('Y-m-d H:i:s')."' 
			WHERE id_article='".$article_id."'";
			
			mysql_query($sql);
			
			}



		
		
	 header('location:../../list_article.php?action=updated&page=list_article');
	
?>
